//
//  LGFollowRecordDetailHead.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/6/26.
//  随访记录详情

#import "LGFollowRecordDetailHead.h"
#define  leftMargin   viewPix(16)
#define  rightMargin  ((Screen_W-viewPix(32))/2.0+viewPix(12))
#define  itemWidht    ((Screen_W-viewPix(32))/2.0-viewPix(32))
@interface LGFollowRecordDetailHead()
/**   */
@property (nonatomic , strong)UIButton *titleBtn;
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *dateTitle;
/**   */
@property (nonatomic , strong)UILabel *dateLabel;
/**   */
@property (nonatomic , strong)UILabel *indexTitle;
/**   */
@property (nonatomic , strong)UILabel *indexLabel;
/**   */
@property (nonatomic , strong)UILabel *numberTitle;
/**   */
@property (nonatomic , strong)UILabel *numberLabel;
/**   */
@property (nonatomic , strong)UILabel *nameTitle;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *doctorTitle;
/**   */
@property (nonatomic , strong)UILabel *doctorLabel;
/**   */
@property (nonatomic , strong)UILabel *typeTitle;
/**   */
@property (nonatomic , strong)UILabel *typeLabel;
/**   */
@property (nonatomic , strong)UILabel *needTitle;
/**   */
@property (nonatomic , strong)UILabel *needLabel;
/**   */
@property (nonatomic , strong)UILabel *contentTitle;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;

@end

@implementation LGFollowRecordDetailHead

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.dateLabel.text = LGNSString(dataDic[@"followup_date"]);
    self.indexLabel.text = [NSString stringWithFormat:@"%@ 号",dataDic[@"followup_no"]];
    self.numberLabel.text = LGNSString(dataDic[@"hospital_bano"]);
    self.nameLabel.text = LGNSString(dataDic[@"realname"]);
    NSArray *needArray = dataDic[@"follow_needs"];
    NSString *needString = @"";
    for (NSInteger i=0; i<needArray.count; i++) {
        needString = (needString.length>0)?[NSString stringWithFormat:@"%@ 、%@",needString,needArray[i]]:needArray[i];
    }
    self.needLabel.text = needString;
    self.contentLabel.text = dataDic[@"followup_content"];
    
    CGFloat needHeight = [needString textHeightWithFont:LGFont(14) maxWidth:Screen_W-viewPix(60)];
    CGFloat contentHeight = [self.contentLabel.text textHeightWithFont:LGFont(14) maxWidth:Screen_W-viewPix(60)];
    if(self.headerViewHeightChanged){
        self.headerViewHeightChanged(viewPix(355)+needHeight+contentHeight);
    }
}

-(void)setDoctorArray:(NSArray *)doctorArray{
    _doctorArray = doctorArray;
    for (NSInteger i=0; i<doctorArray.count; i++) {
        NSDictionary *tempDic = doctorArray[i];
        if([tempDic[@"system_user_id"] integerValue] == [self.dataDic[@"system_user_id"] integerValue]){
            self.doctorLabel.text = LGNSString(tempDic[@"doctor_name"]);
            break;
        }
    }
}

-(void)setTypeArray:(NSArray *)typeArray{
    _typeArray = typeArray;
    for (NSInteger i=0; i<typeArray.count; i++) {
        NSDictionary *tempDic = typeArray[i];
        if([tempDic[@"code"] isEqualToString:self.dataDic[@"followup_type"]]){
            self.typeLabel.text = LGNSString(tempDic[@"title"]);
            break;
        }
    }
}

-(void)createSubView{
    self.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self addSubview:self.titleBtn];
    [self addSubview:self.baseView];
    [self.baseView addSubview:self.dateTitle];
    [self.baseView addSubview:self.dateLabel];
    [self.baseView addSubview:self.indexTitle];
    [self.baseView addSubview:self.indexLabel];
    [self.baseView addSubview:self.numberTitle];
    [self.baseView addSubview:self.numberLabel];
    [self.baseView addSubview:self.nameTitle];
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.doctorTitle];
    [self.baseView addSubview:self.doctorLabel];
    [self.baseView addSubview:self.typeTitle];
    [self.baseView addSubview:self.typeLabel];
    [self.baseView addSubview:self.needTitle];
    [self.baseView addSubview:self.needLabel];
    [self.baseView addSubview:self.contentTitle];
    [self.baseView addSubview:self.contentLabel];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(viewPix(48));
        make.left.equalTo(self).offset(viewPix(16));
        make.right.equalTo(self).offset(-viewPix(16));
        make.bottom.equalTo(self).offset(-viewPix(10));
    }];
    [self.needLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.needTitle.mas_bottom).offset(viewPix(8));
        make.left.equalTo(self.baseView).offset(leftMargin);
        make.right.equalTo(self.baseView).offset(-viewPix(12));
    }];
    [self.contentTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.needLabel.mas_bottom).offset(viewPix(16));
        make.left.equalTo(self.baseView).offset(leftMargin);
        make.width.equalTo(@(itemWidht));
        make.height.equalTo(@(21));
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentTitle.mas_bottom).offset(viewPix(8));
        make.left.right.equalTo(self.needLabel);
    }];
}

-(UIButton *)titleBtn{
    if(!_titleBtn){
        _titleBtn = [UIButton buttonWithTitle:@"线下复查" titleFont:LGFontWeight(17, UIFontWeightMedium) textColor:@"#333333" imageName:@"添加随访-线下复查"];
        _titleBtn.frame = CGRectMake(0, viewPix(8), Screen_W, viewPix(40));
        _titleBtn.userInteractionEnabled = NO;
    }
    return _titleBtn;
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:10];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UILabel *)dateTitle{
    if(!_dateTitle){
        _dateTitle = [UILabel lableWithText:@"日期" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _dateTitle.frame = CGRectMake(leftMargin, viewPix(14), itemWidht, 21);
    }
    return _dateTitle;
}

-(UILabel *)dateLabel{
    if(!_dateLabel){
        _dateLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
        _dateLabel.frame = CGRectMake(leftMargin, kMaxY(self.dateTitle.frame)+viewPix(8), itemWidht, 20);
    }
    return _dateLabel;
}

-(UILabel *)indexTitle{
    if(!_indexTitle){
        _indexTitle = [UILabel lableWithText:@"序号" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _indexTitle.frame = CGRectMake(rightMargin, viewPix(14), itemWidht, 21);
    }
    return _indexTitle;
}

-(UILabel *)indexLabel{
    if(!_indexLabel){
        _indexLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
        _indexLabel.frame = CGRectMake(rightMargin, kMaxY(self.indexTitle.frame)+viewPix(8), itemWidht, 20);
    }
    return _indexLabel;
}


-(UILabel *)numberTitle{
    if(!_numberTitle){
        _numberTitle = [UILabel lableWithText:@"登记号" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _numberTitle.frame = CGRectMake(leftMargin, kMaxY(self.dateLabel.frame)+viewPix(16), itemWidht, 21);
    }
    return _numberTitle;
}

-(UILabel *)numberLabel{
    if(!_numberLabel){
        _numberLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
        _numberLabel.frame = CGRectMake(leftMargin, kMaxY(self.numberTitle.frame)+viewPix(8), itemWidht, 20);
    }
    return _numberLabel;
}

-(UILabel *)nameTitle{
    if(!_nameTitle){
        _nameTitle = [UILabel lableWithText:@"姓名" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _nameTitle.frame = CGRectMake(rightMargin, kMinY(self.numberTitle.frame), itemWidht, 21);
    }
    return _nameTitle;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
        _nameLabel.frame = CGRectMake(rightMargin, kMaxY(self.nameTitle.frame)+viewPix(8), itemWidht, 20);
    }
    return _nameLabel;
}


-(UILabel *)doctorTitle{
    if(!_doctorTitle){
        _doctorTitle = [UILabel lableWithText:@"医生" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _doctorTitle.frame = CGRectMake(leftMargin, kMaxY(self.numberLabel.frame)+viewPix(16), itemWidht, 21);
    }
    return _doctorTitle;
}

-(UILabel *)doctorLabel{
    if(!_doctorLabel){
        _doctorLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
        _doctorLabel.frame = CGRectMake(leftMargin, kMaxY(self.doctorTitle.frame)+viewPix(8), itemWidht, 20);
    }
    return _doctorLabel;
}

-(UILabel *)typeTitle{
    if(!_typeTitle){
        _typeTitle = [UILabel lableWithText:@"类型" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _typeTitle.frame = CGRectMake(rightMargin, kMinY(self.doctorTitle.frame), itemWidht, 21);
    }
    return _typeTitle;
}

-(UILabel *)typeLabel{
    if(!_typeLabel){
        _typeLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
        _typeLabel.frame = CGRectMake(rightMargin, kMaxY(self.typeTitle.frame)+viewPix(8), itemWidht, 20);
    }
    return _typeLabel;
}

-(UILabel *)needTitle{
    if(!_needTitle){
        _needTitle = [UILabel lableWithText:@"问诊需求" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _needTitle.frame = CGRectMake(leftMargin, kMaxY(self.doctorLabel.frame)+viewPix(16), itemWidht, 21);
    }
    return _needTitle;
}

-(UILabel *)needLabel{
    if(!_needLabel){
        _needLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:0];
        _needLabel.frame = CGRectMake(leftMargin, kMaxY(self.needTitle.frame)+viewPix(8), Screen_W-viewPix(60), 20);
    }
    return _needLabel;
}

-(UILabel *)contentTitle{
    if(!_contentTitle){
        _contentTitle = [UILabel lableWithText:@"病情描述" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _contentTitle.frame = CGRectMake(leftMargin, kMaxY(self.needLabel.frame)+viewPix(16), itemWidht, 21);
    }
    return _contentTitle;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:0];
        _contentLabel.frame = CGRectMake(leftMargin, kMaxY(self.contentTitle.frame)+viewPix(8), Screen_W-viewPix(60), 20);
    }
    return _contentLabel;
}

@end
